#include "SysUpAdminDialog.h"
#include "ui_SysUpAdminDialog.h"
#include "SysDAL.h"
#include <QMessageBox>
#include <QDebug>
#include <QDateTime>

SysUpAdminDialog::SysUpAdminDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SysUpAdminDialog)
{
    ui->setupUi(this);
}

SysUpAdminDialog::~SysUpAdminDialog()
{
    delete ui;
}

void SysUpAdminDialog::getArg(QStringList varList)
{
    ui->lineID->setText(varList[0]);
//    ui->linePasswd->setText(varList[1]);
    ui->lineName->setText(varList[2]);
    ui->spinBoxAge->setValue(varList[4].toInt());
    ui->lineIDNumber->setText(varList[5]);
    ui->lineTel->setText(varList[6]);
    ui->comboBox->setItemText(0,QObject::tr("普通管理员"));
    ui->comboBox->setItemText(1,QObject::tr("超级管理员"));
    if(varList[3]=="男") ui->radioMan->setChecked(true);
    else if(varList[3]=="女") ui->radioWoman->setChecked(true);
    if(varList[8].toInt()==0) ui->comboBox->setCurrentText(QObject::tr("普通管理员"));
    else if(varList[8].toInt()==1) ui->comboBox->setCurrentText(QObject::tr("超级管理员"));
}

void SysUpAdminDialog::on_BtnAdd_clicked()
{
    TypeAdmin NewInfo;
    NewInfo.AdminId=ui->lineID->text();
    NewInfo.PassWd=ui->linePasswd->text();
    NewInfo.Name=ui->lineName->text();
    NewInfo.Tel=ui->lineTel->text();
    NewInfo.IdNumber=ui->lineIDNumber->text();
    NewInfo.Age=ui->spinBoxAge->text().toInt();
    NewInfo.Power=ui->comboBox->currentIndex();
    NewInfo.WorkDate=QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
    bool sex1 = ui->radioMan->isChecked();
    bool sex2 = ui->radioWoman->isChecked();
    if(sex1)
        NewInfo.Sex=ui->radioMan->text();
    if(sex2)
        NewInfo.Sex=ui->radioWoman->text();
    ExecStatus modify=SysDBL::AdminModify(NewInfo);
    if(modify.Status)
    {
        QMessageBox::warning(this,QObject::tr("提示"),QObject::tr("你好， %1 ！你的信息修改成功").arg(NewInfo.Name));
    }
    else
    {
        QMessageBox::warning(this,QObject::tr("提示"),QObject::tr("修改失败，错误反馈如下：\n")+modify.StatusInfo);
    }
}



void SysUpAdminDialog::on_BtnQuit_clicked()
{
    this->close();
}
